<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
    <style>
        .layui-form-select dl{
        max-height: 100px; //原值为300，调节高度建议为50的倍数
        }
    </style>
</head>
<body style=" overflow-x:hidden;" >
<div class="layui-container">

    <form class=" layui-form">
        <div class="layui-row">
            <div class="layui-col-md12">
                <fieldset class="layui-elem-field " style="margin-top: 20px;">
                    <legend>车辆管理</legend>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">车牌号</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input   type="text" name="cph"   lay-verify="required" placeholder="请输入"  class="layui-input"   >
                            </div>

                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 56px">档案编号</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="dabh" autocomplete="off" class="layui-input"  >
                                <input type="hidden" lay-verify="" name="clid"  >
                                <input   type="hidden" name="isU"    id="isU"   >
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 80px">主(挂)车车号</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="zgcch" autocomplete="off" class="layui-input"  >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 56px">所属部门</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="ssbm" autocomplete="off" class="layui-input"  >
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">驾驶员</label>
                            <input type="hidden" name="sjid" id="sjid">
                            <div class="layui-input-inline" style="width: 150px;" >
                                <select id="jsy" name="sjid" lay-filter="jsy" lay-search >

                                </select>
                            </div>

                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 56px">油卡号</label>
                            <input type="hidden" name="ykid" id="ykid">
                            <div class="layui-input-inline" style="width: 150px;">
                                <select id="ykh" name="ykid" lay-filter="ykh" lay-search>

                                </select>

                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"  style="width: 80px" >是否分配</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input class="layui-input" id="sffp" name="sffp"  >
                            </div>
                        </div>
                        <div class="layui-inline" id="clzdSelcet" style="display: none">
                            <label class="layui-form-label" style="width: 58px">车辆状态</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <select id="clzt" name="clzt" lay-filter="clzt">
                                    <option value="">请选择</option>
                                    <option value="维修">维修</option>
                                    <option value="停运">停运</option>
                                    <option value="报废">报废</option>
                                    <option value="转出">转出</option>
                                    <option value="可用">可用</option>

                                </select>

                            </div>
                        </div>


                    </div>





                </fieldset>
            </div>
        </div>

        <button type="button" class="layui-btn layui-btn-normal"  id="modiInfo" style="width: 10%; position: absolute;left: 55%" >修改信息</button>
        <button id="modiSub" class="layui-btn layui-btn-normal layui-btn-disabled" disabled lay-submit lay-filter="update" style="width: 10%; position: absolute;left: 35%"  >立即提交</button>
    </form>
</div>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script>
    layui.use(['table','form','element' ],function () {

        var table = layui.table;
        var $ = layui.$;
        var element = layer.element;
        var form = layui.form;
        var areaInfo;


        $(".layui-input").addClass("layui-disabled");
        $(".layui-input").attr("disabled",true);
        $("select").attr("disabled","disabled");
        if($("#isU").val() == "false"){
            $("#modiInfo").attr("disabled",true);
            $("#modiInfo").addClass("layui-btn-disabled");
        }
        $("#modiInfo").on('click',function(){

            $("#modiSub").removeClass("layui-btn-disabled");
            $("#modiSub").removeAttr("disabled");

            $("#modiInfo").addClass("layui-btn-disabled");
            $("#modiInfo").attr("disabled",true);

            $("#jsy,#ykh,#clzt").removeClass("layui-btn-disabled");
            $("#jsy,#ykh,#clzt").removeAttr("disabled");
            form.render('select');
        });

        form.on('select(jsy)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            if(data.elem !=""){
                $("#sffp").val("已分配");
                $("#clzdSelcet").hide();
            } else {
            $("#sffp").val("未分配")
            $("#clzdSelcet").show();
        }
            console.log(data.value); //得到被选中的值
            if(data.value != ""){
                $("#sffp").val("已分配");
                $("#clzdSelcet").hide();
                $("#clzt").val("");
//                $("#modiInfo").addClass("layui-btn-disabled");
//                $("#modiInfo").attr("disabled",true);
            }else {
                $("#sffp").val("未分配")
                $("#clzdSelcet").show();
            }
            console.log(data.othis); //得到美化后的DOM对象
        });


        //渲染车辆状态
        if($("#sffp").val() == "未分配"){
            $("#clzdSelcet").show();
        }else if($("#sffp").val() == "已分配"){
            $("#clzdSelcet").hide();
//            $("#modiInfo").addClass("layui-btn-disabled");
//            $("#modiInfo").attr("disabled",true);
        }

        //渲染 select
        $.ajax({
            url: contextPath+"/driverlist?zzzt=在职",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                $("#jsy").append("<option value=''>请选择</option>");
                for(var i in res.list){
                    if($("#sjid").val() == res.list[i].sjid){
                        var option = "<option selected value='"+ res.list[i].sjid+ "'>"+res.list[i].jsyxm+"/"+res.list[i].jsysj+"</option>";
                    }else {
                        var option = "<option value='"+ res.list[i].sjid+ "'>"+res.list[i].jsyxm+"/"+res.list[i].jsysj+"</option>";
                    }

                    $("#jsy").append(option);
                };
                form.render('select');
            }
        });

        $.ajax({
            url: contextPath+"/oilcardlist",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                $("#ykh").append("<option value=''>请选择</option>");

                for(var i in res.list){
                    if($("#ykid").val() == res.list[i].ykid){
                        var option = "<option  selected value='"+ res.list[i].ykid+ "'>"+res.list[i].ykh+"</option>";
                    }else {
                        var option = "<option value='"+ res.list[i].ykid+ "'>"+res.list[i].ykh+"</option>";
                    }

                    $("#ykh").append(option);
                };
                form.render('select');
            }
        });










        form.on('submit(update)', function(data){
            $("input").css("border","");
                console.log(JSON.stringify(data.field));
            $.ajax({
                url: contextPath+"/carmgmt/",
                type: "PUT",
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify(data.field) ,
                dataType:"json",
                success: function(res) {
                    console.log(res);
                    updateSuccess($,layer,res)
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });

</script>
</body>
</html>